package io.bhex.baselib.observer;

import io.reactivex.Observable;
import io.reactivex.Observer;
import io.reactivex.disposables.Disposable;

/**
 * created by gongdongyang
 * on 2020/2/29
 */
public  abstract class BaseObserver<T>  implements Observer<T> {


    private Disposable disposable;

    public boolean isNeedShowtoast = true;


    public BaseObserver() {

    }

    public BaseObserver(boolean showToast){this.isNeedShowtoast = showToast;}


    public void dispose() {
        if (disposable != null && !disposable.isDisposed()){
            disposable.dispose();
        }
    }

    public boolean isDisposed() {
        return (disposable != null && disposable.isDisposed());
    }


    @Override
    public void onSubscribe(Disposable d) {
        this.disposable = d;
    }

    @Override
    public void onNext(T t) {
        onSuccess(t);
    }

    @Override
    public void onError(Throwable e) {
        onFailure(1,"");
    }

    @Override
    public void onComplete() {

    }


    public abstract void onSuccess(T t);

    public void onFailure(int code, String errorMsg){

    }
}
